import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import { viteStaticCopy } from 'vite-plugin-static-copy';

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
    viteStaticCopy({
      targets: [
        {
          src: 'node_modules/amis/sdk/**/*',
          dest: 'amis/sdk'
        }
      ]
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  // 添加代理配置
  server: {
    // 添加 host 配置，设置为 0.0.0.0 可以让外部访问
    host: '0.0.0.0', 
    // 设置端口为 9000
    port: 9000, 
    proxy: {
      // 假设你要代理所有以 /api 开头的请求
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api')
      },
      '/image-server': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/image-server/, '/')
      },
      '/edit': {
        target: 'http://localhost:8001/#/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/edit/, '/edit')
      }
    }
  }
})
